home *** CD-ROM | disk | FTP | other *** search
- /* AddCatalog.c */
- /*
- * AddCatalog.c
- * Copyright © 1992-93 Apple Computer Inc. All Rights Reserved.
- *
- * Add a catalog (expressed as a FSSpec) to our private list of catalogs. Note
- * that AddCatalog allocates memory and, hence, must not be called from an I/O
- * completion or interrupt routine.
- */
- #include "DTSSampleCSAM.h"
-
- OSErr
- AddCatalog(
- register DTSSampleCSAMInfoPtr infoPtr,
- DirParamBlockPtr pb
- )
- {
- OSErr status;
- CatalogInfoPtr newCatalog;
- RecordID rid;
- short setupRefNum;
- short pabRefNum;
- FSSpec pabSpec;
- AttributeType attributeType;
- AuthGetLocalIdentityPB authParamBlock;
- #define ADD (pb->addDSAMDirectoryPB)
- #define NEW (*newCatalog)
-
- LogText('AddS', "\pAddCatalog entry");
- LogRString('AddD', ADD.directoryName);
- status = ADASGetOCESetupInfo(&rid, &setupRefNum);
- LogStatus('AddD', status, "\pADASGetOCESetupInfo");
- if (status == noErr) {
- /*
- * This couldn't be stored in a resource, for some bizarre
- * reason. Perhaps the code hadn't setup the current resource
- * file correctly.
- */
- OCECToRString(
- kPDAliasAttrTypeBody, /* Note: C-string */
- smRoman,
- (RStringPtr) &attributeType,
- kAttributeTypeMaxBytes
- );
- }
- if (status == noErr) {
- rid.local.recordName = NULL;
- rid.local.recordType = NULL;
- rid.rli = NULL;
- OCECopyCreationID(&ADD.directoryRecordCID, &rid.local.cid);
- pabSpec.vRefNum = 0;
- /*
- * Get the local identity. If this fails, use zero (guest).
- */
- (void) AuthGetLocalIdentity(
- (AuthParamBlockPtr) &authParamBlock,
- FALSE /* Synchronous */
- );
- LogStatus('AddD', authParamBlock.ioResult, "\pAuthGetLocalIdentity");
- if (authParamBlock.ioResult != noErr)
- authParamBlock.theLocalIdentity = 0; /* Use "guest" */
- status = ADASLookupAttributeValue(
- &rid,
- setupRefNum,
- authParamBlock.theLocalIdentity, /* Use owner ident */
- kAliasBufferSize,
- FALSE, /* Don't include start */
- &attributeType,
- OCENullCID(),
- (long) &pabSpec,
- (ForEachAttrValue) GetPABFSSpecCB
- );
- LogStatus('AddD', status, "\pADASLookupAttributeValue");
- }
- if (status == noErr) {
- LogText('AddD', "\pCalling ADASOpenPAB");
- status = ADASOpenPAB(
- &pabSpec,
- fsRdWrPerm,
- &pabRefNum
- );
- LogStatus('AddD', status, "\pADASOpenPAB");
- }
- if (status == noErr) {
- /*
- * The new catalog used to be created on the current heap. I changed
- * this to creating it on the system heap because I'm paranoid about
- * heap trashing.
- */
- newCatalog = (CatalogInfoPtr) NewPtrSysClear(sizeof (CatalogInfo));
- status = MemError();
- LogError('AddD', status);
- if (status == noErr) {
- NEW.refNum = pabRefNum;
- OCECopyCreationID(&ADD.directoryRecordCID, &NEW.creationID);
- OCECopyDirDiscriminator(&ADD.discriminator, &NEW.discriminator);
- OCECopyRString(
- (RString *) ADD.directoryName,
- (RString *) &NEW.directoryName,
- kDirectoryNameMaxBytes
- );
- /*
- * Finally, add this catalog to the list of active catalogs. We
- * really don't need an operating system queue here, but Enqueue
- * does what we want and doesn't do what we don't want.
- */
- Enqueue((QElemPtr) newCatalog, &INFO.catalogQHdr);
- }
- else {
- /*
- * We couldn't allocate memory for this catalog. All we can do is
- * close the PAB. Ignore any error from ADASClosePAB since we
- * have a real error now.
- */
- (void) ADASClosePAB(pabRefNum);
- }
- }
-
- LogStatus('AddD', status, "\pAddCatalog exit");
- LogRString('AdXt', ADD.directoryName);
- return (status);
- #undef ADD
- }
-